package com.wenx;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.Getter;
import lombok.Setter;

/**
 * 获取服务器返回的结果
 */
@Getter
@Setter
public class RPCClientHandler extends SimpleChannelInboundHandler<Object> {


    private Object result;

    public Object getRPCResult() {
        return getResult();
    }

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, Object o) throws Exception {
        setResult(o);
        channelHandlerContext.close();
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {

        cause.printStackTrace();

        ctx.close();
    }
}
